<template>
  <div class="header">
    <div class="header-container">
      <router-link :to="'/'">
        <div class="logo">
          <img src="~/assets/img/logo.svg" width="26px" height="26px">
          <span class="text-primary" style="margin-left: 10px">天天博客</span>
        </div>
      </router-link>

      <ul class="tab link-list">
        <li class="tab-item">
          <nuxt-link :to="{ path: '/article', query: {page: '1'}}">首页</nuxt-link>
        </li>
        <li class="tab-item">
          <nuxt-link :to="{path: '/category'}">分类</nuxt-link>
        </li>
        <li class="tab-item">
          <nuxt-link :to="{path: '/tag'}">标签</nuxt-link>
        </li>
        <li class="tab-item">
          <nuxt-link :to="{path: '/archive'}">归档</nuxt-link>
        </li>
        <li class="tab-item">
          <nuxt-link :to="{path: '/about'}">关于</nuxt-link>
        </li>
        <li class="tab-item">
          <nuxt-link :to="{path: '/article/publish'}">发布</nuxt-link>
        </li>


        <li class="tab-item" style="padding-left: 120px;">
          <a @click="to('/login')">登录</a>
        </li>
      </ul>
      <div class="header-menu">
        <div class="header-menu-icon" @click="toggle">
          <span class="icon-th-list" style="font-size: 24px"></span>
        </div>
        <div class="header-menu-list" :class="{ 'open': menuOpen }">
          <ul>
            <li class="header-menu-item text-primary">
              <a @click="to('/article',{page: '1'})">首页</a>
            </li>
            <li class="header-menu-item">
              <a @click="to('/category')">分类</a>
            </li>
            <li class="header-menu-item">
              <a @click="to('/tag')">标签</a>
            </li>
            <li class="header-menu-item">
              <a @click="to('/archive')">归档</a>
            </li>
            <li class="header-menu-item">
              <a @click="to('/about')">关于</a>
            </li>
            <li class="header-menu-item">
              <a @click="to('/article/publish')">发布</a>
            </li>
          </ul>
        </div>
      </div>


    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  export default {
    data () {
      return {
        menuOpen: false
      }
    },
    methods: {
      toggle () {
        this.menuOpen = !this.menuOpen
      },
      to (url, query) {
        this.$router.push({path: url, query: query})
        this.toggle()
      }
    }
  }
</script>

<style scoped>
  a {
    color: #5764c6;
    text-decoration: none;
  }

  .header {
    position: fixed;
    background-color: rgba(255, 255, 255, 0.98);
    box-shadow: 0px 1px 0px #5764c6;
    border: none;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 200;
    transition: background 0.5s;
    height: 70px;
  }

  .header-container {
    max-width: 1200px;
    height: 40px;
    margin: 0 auto;
    padding: 15px 30px;
    font-size: .9rem;
    position: relative;
  }

  .header-container .logo {
    display: flex;
    align-items: center;
    float: left;
    margin: 5px 0;
    font-weight: 600;
    font-size: 1.5em;
  }

  .header-container .tab {
    list-style: none;
    float: right;
    padding: 0;
    margin: 5px 0;
    border-bottom: none;
  }

  .header-container .tab .tab-item {
    display: inline-block;
    margin: 0 8px;
  }

  .header-container .tab .tab-item a {
    border-bottom: .1rem solid transparent;
    display: block;
    margin: 0;
    padding: .4rem .2rem .3rem .2rem;
    color: #50596c;
    text-decoration: none;
  }

  .header-container .tab .tab-item a.active {
    border-bottom-color: #5764c6;
    color: #5764c6;
  }

  @media screen and (max-width: 600px) {
    .link-list {
      display: none;
    }
  }

  .link-list .tab-item {
    display: inline-block;
    margin: 0 8px;
  }

  @media screen and (min-width: 600px) {
    .header-menu {
      display: none;
    }
  }

  .header-container .header-menu-icon {
    display: flex;
    align-items: center;
    float: right;
    height: 40px;
    line-height: 40px;
  }

  .header-container .header-menu-list {
    max-height: 0;
    position: fixed;
    left: 0;
    top: 52px;
    z-index: 99;
    width: 100%;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.98);
    -webkit-transition: max-height 0.3s ease;
    transition: max-height 0.3s ease;
  }

  .header-container .open {
    max-height: 300px;
    transition-delay: 0.1s;
  }

  .header-container .header-menu-list > ul {
    margin: 0;
    padding: 0;
  }

  .header-container .header-menu-list .header-menu-item {
    position: relative;
    list-style: none;
    text-align: center;
    padding: 10px 0;
  }

  .header-container .header-menu-list .header-menu-item:after {
    content: '';
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    border-bottom: 1px solid #e5e5e5;
    -webkit-transform: scaleY(0.5);
    transform: scaleY(0.5);
  }

</style>
